﻿<UserControl x:Class="SiliconStudio.Meet.EjpControls.PenLineButton"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
    Height="41" Width="Auto">
    <UserControl.Resources>

        <LinearGradientBrush x:Key="defB_ItemBG_on" StartPoint="0.5,0.0708979" EndPoint="0.5,1.2239">
            <LinearGradientBrush.GradientStops>
                <GradientStop Color="#FFFFFFFF" Offset="0"/>
                <GradientStop Color="#FFCBCBCB" Offset="1"/>
            </LinearGradientBrush.GradientStops>
        </LinearGradientBrush>

        <LinearGradientBrush x:Key="defB_ItemBG_off" StartPoint="0.5,0" EndPoint="0.5,1.00001">
            <LinearGradientBrush.GradientStops>
                <GradientStop Color="#FFC5C5C5" Offset="0"/>
                <GradientStop Color="#FFC5C5C5" Offset="0.28889"/>
                <GradientStop Color="#FF9E9D9E" Offset="0.89444"/>
                <GradientStop Color="#FF898989" Offset="0.98334"/>
                <GradientStop Color="#FF898989" Offset="1"/>
            </LinearGradientBrush.GradientStops>
        </LinearGradientBrush>

        <LinearGradientBrush x:Key="defB_ItemBG_active" StartPoint="0.5,-0.00265201" EndPoint="0.5,1.04974">
            <LinearGradientBrush.GradientStops>
                <GradientStop Color="#FFF8E883" Offset="0"/>
                <GradientStop Color="#FFFBF5B6" Offset="0.139"/>
                <GradientStop Color="#FFF8E279" Offset="1"/>
                <GradientStop Color="#FFFCB142" Offset="0.562"/>
            </LinearGradientBrush.GradientStops>
        </LinearGradientBrush>

        <DrawingBrush x:Key="bgClear">
            <DrawingBrush.Drawing>
                <DrawingGroup>
                    <DrawingGroup.Children>
                        <GeometryDrawing Brush="{StaticResource defB_ItemBG_on}" Geometry="F1 M 54.0053,47.3373C 54.0053,51.02 51.02,54.004 47.3387,54.004L 6.66667,54.004C 2.98397,54.004 0,51.02 0,47.3373L 0,6.66666C 0,2.98535 2.98397,0 6.66667,0L 47.3387,0C 51.02,0 54.0053,2.98535 54.0053,6.66666L 54.0053,47.3373 Z "/>
                    </DrawingGroup.Children>
                </DrawingGroup>
            </DrawingBrush.Drawing>
        </DrawingBrush>

        <DrawingBrush x:Key="bgClear_pressed">
            <DrawingBrush.Drawing>
                <DrawingGroup>
                    <DrawingGroup.Children>
                        <GeometryDrawing Brush="{StaticResource defB_ItemBG_active}" Geometry="F1 M 54.0053,47.3373C 54.0053,51.02 51.02,54.004 47.3387,54.004L 6.66667,54.004C 2.98397,54.004 0,51.02 0,47.3373L 0,6.66666C 0,2.98535 2.98397,0 6.66667,0L 47.3387,0C 51.02,0 54.0053,2.98535 54.0053,6.66666L 54.0053,47.3373 Z "/>
                    </DrawingGroup.Children>
                </DrawingGroup>
            </DrawingBrush.Drawing>
        </DrawingBrush>

        <DrawingBrush x:Key="bgClear_off">
            <DrawingBrush.Drawing>
                <DrawingGroup>
                    <GeometryDrawing Brush="{StaticResource defB_ItemBG_off}" Geometry="F1 M 54.0053,47.3373C 54.0053,51.02 51.02,54.004 47.3387,54.004L 6.66667,54.004C 2.98397,54.004 0,51.02 0,47.3373L 0,6.66666C 0,2.98535 2.98397,0 6.66667,0L 47.3387,0C 51.02,0 54.0053,2.98535 54.0053,6.66666L 54.0053,47.3373 Z "/>
                </DrawingGroup>
            </DrawingBrush.Drawing>
        </DrawingBrush>
    </UserControl.Resources>
    <Grid>
        <Grid.Resources>

            <Style x:Key="ComboBoxFocusVisual">
                <Setter Property="Control.Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Rectangle SnapsToDevicePixels="true" Margin="4,4,21,4" Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1"/>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <LinearGradientBrush x:Key="ButtonNormalBackground" EndPoint="0,1" StartPoint="0,0">
                <GradientStop Color="#F3F3F3" Offset="0"/>
                <GradientStop Color="#EBEBEB" Offset="0.5"/>
                <GradientStop Color="#DDDDDD" Offset="0.5"/>
                <GradientStop Color="#CDCDCD" Offset="1"/>
            </LinearGradientBrush>
            <SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070"/>

           
            <Geometry x:Key="DownArrowGeometry">M 0 0 L 3.5 4 L 7 0 Z</Geometry>
            <Style x:Shared="false" x:Key="ComboBoxReadonlyToggleButton" TargetType="{x:Type ToggleButton}">
                <Setter Property="OverridesDefaultStyle" Value="true"/>
                <Setter Property="IsTabStop" Value="false"/>
                <Setter Property="Focusable" Value="false"/>
                <Setter Property="ClickMode" Value="Press"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ToggleButton}">
                           
                            <Grid Height="Auto">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="20"/>
                                </Grid.ColumnDefinitions>
                                <Rectangle HorizontalAlignment="Right" x:Name="bgSquare" Margin="0,0,0,0" Width="45" Fill="{DynamicResource bgClear}" Stroke="{x:Null}" Grid.ColumnSpan="2"/>
                                <Path HorizontalAlignment="Center" Margin="0,0,0,0" x:Name="Arrow" VerticalAlignment="Center" Fill="Black" Data="{StaticResource DownArrowGeometry}" Width="Auto" Grid.Column="1"/>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsChecked" Value="true">
                                    <Setter Property="Fill" TargetName="bgSquare" Value="{StaticResource bgClear_pressed}"/>
                                </Trigger>
                                <Trigger Property="IsChecked" Value="false">
                                    <Setter Property="Fill" TargetName="bgSquare" Value="{StaticResource bgClear}"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            
            <Style x:Shared="false"  x:Key="SwatchTemplate" TargetType="{x:Type ComboBox}">
                <Setter Property="FocusVisualStyle" Value="{StaticResource ComboBoxFocusVisual}"/>
                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
                <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
                <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
                <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
                <Setter Property="Padding" Value="4,3"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ComboBox}">
                            <Grid SnapsToDevicePixels="true" x:Name="MainGrid">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
                                </Grid.ColumnDefinitions>
                                <Popup AllowsTransparency="true" IsOpen="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Margin="1" x:Name="PART_Popup" Grid.ColumnSpan="2">
                                    <Microsoft_Windows_Themes:SystemDropShadowChrome MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding Path=ActualWidth, ElementName=MainGrid}" x:Name="Shdw" Color="Transparent">
                                        <Border x:Name="DropDownBorder" BorderThickness="2" BorderBrush="White">
                                            <Border.Background>
                                                <LinearGradientBrush EndPoint="0.5,1.66" StartPoint="0.5,-2.265">
                                                    <GradientStop Color="#FF4AADC3" Offset="0.005"/>
                                                    <GradientStop Color="#FFFFFFFF" Offset="0.596"/>
                                                    <GradientStop Color="#FF53B0E4" Offset="1"/>
                                                </LinearGradientBrush>
                                            </Border.Background>
                                            <ScrollViewer CanContentScroll="true">
                                                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.DirectionalNavigation="Contained"/>
                                            </ScrollViewer>
                                        </Border>
                                    </Microsoft_Windows_Themes:SystemDropShadowChrome>
                                </Popup>
                                <ToggleButton x:Name="tgDlButton" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" Style="{StaticResource ComboBoxReadonlyToggleButton}" Grid.ColumnSpan="2" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"/>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
                                    <Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/>
                                    <Setter Property="Color" TargetName="Shdw" Value="#71000000"/>
                                </Trigger>
                                <Trigger Property="HasItems" Value="false">
                                    <Setter Property="Height" TargetName="DropDownBorder" Value="95"/>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="false">
                                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                                    <Setter Property="IsEnabled" Value="false" TargetName="tgDlButton"/>
                                </Trigger>
                                <Trigger Property="IsGrouping" Value="true">
                                    <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <DrawingBrush x:Key="PenButtonBG">
                <DrawingBrush.Drawing>
                    <DrawingGroup>
                        <DrawingGroup.Children>
                            <GeometryDrawing Brush="{StaticResource defB_ItemBG_on}" Geometry="F1 M 54.0053,47.3373C 54.0053,51.02 51.02,54.004 47.3387,54.004L 6.66667,54.004C 2.98397,54.004 0,51.02 0,47.3373L 0,6.66666C 0,2.98535 2.98397,0 6.66667,0L 47.3387,0C 51.02,0 54.0053,2.98535 54.0053,6.66666L 54.0053,47.3373 Z "/>
                            <GeometryDrawing Geometry="F1 M 14.0827,31.0087L 38.9613,10.134L 44.5933,16.846L 19.7147,37.722C 19.7147,37.722 9.29333,41.0674 9.22135,40.8073C 9.05599,40.2167 14.0827,31.0087 14.0827,31.0087 Z ">
                                <GeometryDrawing.Brush>
                                    <LinearGradientBrush StartPoint="0.357295,0.426979" EndPoint="0.709873,0.426979">
                                        <LinearGradientBrush.RelativeTransform>
                                            <TransformGroup>
                                                <SkewTransform CenterX="0.357295" CenterY="0.426979" AngleX="8.11838" AngleY="0"/>
                                                <RotateTransform CenterX="0.357295" CenterY="0.426979" Angle="49.0591"/>
                                            </TransformGroup>
                                        </LinearGradientBrush.RelativeTransform>
                                        <LinearGradientBrush.GradientStops>
                                            <GradientStop Color="#FF2F7EC2" Offset="0"/>
                                            <GradientStop Color="#FF52C1E2" Offset="1"/>
                                        </LinearGradientBrush.GradientStops>
                                    </LinearGradientBrush>
                                </GeometryDrawing.Brush>
                            </GeometryDrawing>
                        </DrawingGroup.Children>
                    </DrawingGroup>
                </DrawingBrush.Drawing>
            </DrawingBrush>

            <DrawingBrush x:Key="PenButtonBG_pressed">
                <DrawingBrush.Drawing>
                    <DrawingGroup>
                        <DrawingGroup.Children>
                            <GeometryDrawing Brush="{StaticResource defB_ItemBG_active}" Geometry="F1 M 54.0053,47.3373C 54.0053,51.02 51.02,54.004 47.3387,54.004L 6.66667,54.004C 2.98397,54.004 0,51.02 0,47.3373L 0,6.66666C 0,2.98535 2.98397,0 6.66667,0L 47.3387,0C 51.02,0 54.0053,2.98535 54.0053,6.66666L 54.0053,47.3373 Z "/>
                            <GeometryDrawing Geometry="F1 M 14.0827,31.0087L 38.9613,10.134L 44.5933,16.846L 19.7147,37.722C 19.7147,37.722 9.29333,41.0674 9.22135,40.8073C 9.05599,40.2167 14.0827,31.0087 14.0827,31.0087 Z ">
                                <GeometryDrawing.Brush>
                                    <LinearGradientBrush StartPoint="0.3955,0.471017" EndPoint="0.795387,0.471017">
                                        <LinearGradientBrush.RelativeTransform>
                                            <TransformGroup>
                                                <SkewTransform CenterX="0.3955" CenterY="0.471017" AngleX="8.12074" AngleY="0"/>
                                                <RotateTransform CenterX="0.3955" CenterY="0.471017" Angle="49.0605"/>
                                            </TransformGroup>
                                        </LinearGradientBrush.RelativeTransform>
                                        <LinearGradientBrush.GradientStops>
                                            <GradientStop Color="#FF2F7EC2" Offset="0"/>
                                            <GradientStop Color="#FF52C1E2" Offset="1"/>
                                        </LinearGradientBrush.GradientStops>
                                    </LinearGradientBrush>
                                </GeometryDrawing.Brush>
                            </GeometryDrawing>
                        </DrawingGroup.Children>
                    </DrawingGroup>
                </DrawingBrush.Drawing>
            </DrawingBrush>

            <DrawingBrush x:Key="PenButtonBG_off">
                <DrawingBrush.Drawing>
                    <DrawingGroup>
                        <DrawingGroup.Children>
                            <GeometryDrawing Brush="{StaticResource defB_ItemBG_off}" Geometry="F1 M 54.0053,47.3373C 54.0053,51.02 51.02,54.004 47.3387,54.004L 6.66667,54.004C 2.98397,54.004 0,51.02 0,47.3373L 0,6.66666C 0,2.98535 2.98397,0 6.66667,0L 47.3387,0C 51.02,0 54.0053,2.98535 54.0053,6.66666L 54.0053,47.3373 Z "/>
                            <GeometryDrawing Brush="#FFAAAAAA" Geometry="F1 M 14.0827,31.0093L 38.9613,10.1333L 44.5933,16.8453L 19.7147,37.72C 19.7147,37.72 9.29333,41.0667 9.22135,40.8053C 9.05599,40.2147 14.0827,31.0093 14.0827,31.0093 Z "/>
                        </DrawingGroup.Children>
                    </DrawingGroup>
                </DrawingBrush.Drawing>
            </DrawingBrush>

            <ControlTemplate x:Key="MTB_PenLine" TargetType="{x:Type ToggleButton}">
                <Grid>
                    <Rectangle Fill="#FFFFFFFF" Stroke="{x:Null}" StrokeThickness="0" Margin="0,0,0,0" x:Name="rectangle"/>
                    <ContentPresenter />
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsChecked" Value="False">
                        <Setter TargetName="rectangle" Property="Fill" Value="{StaticResource PenButtonBG}"/>
                    </Trigger>
                    <Trigger Property="IsChecked" Value="True">
                        <Setter TargetName="rectangle" Property="Fill" Value="{StaticResource PenButtonBG_pressed}"/>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="rectangle" Property="Fill" Value="{StaticResource PenButtonBG_off}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>

        </Grid.Resources>

        <ComboBox Style="{DynamicResource SwatchTemplate}" BorderBrush="{x:Null}" 
                  Foreground="{x:Null}" Background="{StaticResource bgClear}"
                  SelectionChanged="SelectedColorChanged" HorizontalAlignment="Right" 
                  x:Name="_cb_AvailableBrushes" Margin="5,0,0,0" Width="55" />
        <Rectangle HorizontalAlignment="Right" Margin="0,5,18,5" VerticalAlignment="Stretch"
                       Fill="Gray" Height="Auto" Width="1" />
        <ToggleButton Template="{StaticResource MTB_PenLine}" BorderBrush="#000000" 
                 BorderThickness="0" HorizontalAlignment="Left" Width="40" Checked="SetActiveColor"
                 Unchecked="UnCheckControlParts" x:Name="_b_toolButton">
            <Rectangle HorizontalAlignment="Center" Margin="5,1,5,5" VerticalAlignment="Bottom"
                       Fill="Black" Width="30" Height="3" x:Name="_r_CurrentColor" />
            
        </ToggleButton>
    </Grid>
</UserControl>
